package com.demo.java.OD251_300.OD254;
import java.util.*;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【天然蓄水库 or 天然蓄水池】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146053541
 */
public class OdMain {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);

            // 读取输入的高度数组
            String[] inputHeights = scanner.nextLine().split(" ");
            int[] heights = Arrays.stream(inputHeights).mapToInt(Integer::parseInt).toArray();

            // 获取最小的高度，用于筛选有效区域
            int minHeight = Arrays.stream(heights).min().getAsInt();

            int maxArea = 0;
            int maxLeftIndex = 0;
            int maxRightIndex = 0;

            // 遍历所有可能的左边界
            for (int i = 0; i < heights.length - 2; i++) {
                int leftHeight = heights[i];

                // 排除最小高度的位置
                if (leftHeight == minHeight) {
                    continue;
                }

                // 计算最大水库容量及其边界
                int[] result = findMaxArea(heights, minHeight, i);

                // 更新最大面积及其边界
                if (result[0] > maxArea) {
                    maxArea = result[0];
                    maxLeftIndex = result[1];
                    maxRightIndex = result[2];
                }
            }

            // 输出最大面积及其边界
            System.out.println(maxArea == 0 ? 0 : maxLeftIndex + " " + maxRightIndex + ":" + maxArea);
        }

        // 计算给定左边界后的最大水库
        private static int[] findMaxArea(int[] heights, int minHeight, int i) {
            int maxArea = 0;
            int maxLeftIndex = 0;
            int maxRightIndex = 0;

            // 遍历右边界
            for (int j = i + 2; j < heights.length; j++) {
                int rightHeight = heights[j];

                // 排除最小高度的位置
                if (rightHeight == minHeight) {
                    continue;
                }

                // 计算当前边界形成的水库
                int height = Math.min(heights[i], rightHeight);
                int area = 0;
                for (int k = i + 1; k < j; k++) {
                    int heightDifference = height - heights[k];

                    // 累加可以存储的水量
                    if (heightDifference > 0) {
                        area += heightDifference;
                    }
                }

                // 更新最大水库
                if (area > maxArea) {
                    maxArea = area;
                    maxLeftIndex = i;
                    maxRightIndex = j;
                } else if (area == maxArea && (maxRightIndex - maxLeftIndex) > (j - i)) {
                    maxLeftIndex = i;
                    maxRightIndex = j;
                }
            }

            return new int[] {maxArea, maxLeftIndex, maxRightIndex};
        }
}